using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;
using umbraco.controls;
using umbraco.cms.businesslogic.language;
using Commerce.Common;

namespace CommerceForUmbraco.adminSection.trees
{
    public class loadManufacturerTree : BaseTree
    {
        public loadManufacturerTree(string application) : base(application) { }

        protected override void CreateRootNode(ref XmlTreeNode rootNode)
        {
                rootNode.Icon = FolderIcon;
                rootNode.OpenIcon = FolderIconOpen;
                rootNode.NodeType = "init" + TreeAlias;
                rootNode.NodeID = "init";
        }

        public override void Render(ref XmlTree tree)
        {
            // get collection values
            Commerce.Common.ManufacturerCollection manufacturers = null;

            manufacturers = new ManufacturerCollection().OrderByAsc("manufacturer").Load();

            foreach (Manufacturer thisMan in manufacturers)
	        {
                XmlTreeNode xNode = XmlTreeNode.Create(this);
                xNode.NodeID = thisMan.ManufacturerID.ToString();
                xNode.Text = thisMan.ManufacturerX;
                xNode.Action = "javascript:openManufacturer(" + thisMan.ManufacturerID + ");";
                xNode.Icon = "statistik.gif";
                xNode.OpenIcon = "statistik.gif";

                tree.Add(xNode);
	        }

        }

        public override void RenderJS(ref StringBuilder Javascript)
        {
                 Javascript.Append(
                    @"
                    function openManufacturer(id) {
	                    parent.right.document.location.href = 'commerce/editManufacturer.aspx?m=' + id;
                    }
                ");
        }
    }
}
